package com.sojoys.artifact.tools;

import java.util.concurrent.ThreadFactory;

public class LogicThreadFactory implements ThreadFactory {
	final ThreadGroup group;
	final String namePrefix;

	public LogicThreadFactory(String threadName) {
		SecurityManager s = System.getSecurityManager();
		group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
		namePrefix = "ConnectionPool-" + threadName;
	}

	@Override
	public Thread newThread(Runnable r) {
		Thread t = new Thread(group, r, namePrefix, 0);
		if (t.isDaemon())
			t.setDaemon(false);
		if (t.getPriority() != Thread.NORM_PRIORITY)
			t.setPriority(Thread.NORM_PRIORITY);
		return t;
	}
}